package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author SunSun
 * @date 2021/10/30
 */
@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /**
     * 环信Id查询用户详情
     * @param huanxinId
     * @return
     */
    @GetMapping("/userinfo")
    public ResponseEntity userinfo(String huanxinId){

        UserInfoVo userInfo=messagesService.findUserInfoByHuanXin(huanxinId);
        return ResponseEntity.ok(userInfo);
    }

    /**
     * 添加好友关系
     * @param map
     * @return
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map){
        String obj = map.get("userId").toString();
        Long aLong = Long.valueOf(obj);
        messagesService.contacts(aLong);
        return ResponseEntity.ok(null);
    }

    /**
     * 查看联系人列表
     */
    @GetMapping("/contacts")
    public ResponseEntity  getcontacts(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize,
                                       String keyword){

        PageResult pr=messagesService.findFriends(page,pagesize,keyword);
        return ResponseEntity.ok(pr);
    }

    @GetMapping("/likes")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr=messagesService.likes(page,pagesize);
        return ResponseEntity.ok(pr);
    }

    @GetMapping("/comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr=messagesService.comments(page,pagesize);
        return ResponseEntity.ok(pr);
    }
    @GetMapping("/loves")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr=messagesService.loves(page,pagesize);
        return ResponseEntity.ok(pr);
    }

    @GetMapping("/announcements")
    public ResponseEntity announcements(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr=messagesService.announcements(page,pagesize);
        return ResponseEntity.ok(pr);
    }

}
